import * as echarts from 'echarts';
export function getOptionsForRankBar(xData, yData, yLabel){
  var option = {
    grid: {
        left: '5%',
        right: '9%',
        bottom: '5%',
        top: '10%',
        containLabel: true,
    },
    legend: {//图例组件，颜色和名字
      icon: 'rect',
      right: 10,
      top: 15,
      itemGap: 16,
      itemWidth: 18,
      itemHeight: 10,
        textStyle: {
          color: '#fff',
          opacity:'0.6',
          fontStyle: 'normal',
          fontFamily: '微软雅黑',
          fontSize: 12,            
      }
  },    
    tooltip: {
        show: false,
        trigger: "item",
        backgroundColor:"rgba(0,0,0,0)",
        borderColor:"rgba(0,0,0,0)",
        triggerOn: "mousemove",
        enterable:true,
        shadowBlur: 0,
        shadowColor: 'rgba(0, 0, 0, 0)',
        padding:[0],
        textStyle: {
          color: '#fff', // 文本颜色
          fontSize: 24, // 文本大小
          fontWeight: 500,
        },
         formatter: "<span style='font-size:16px;'>{c}次</span>",
    },
    // backgroundColor: '#031d33',
    xAxis: {
        show: true,
        type: 'value',
        // data:xData
        splitNumber: 7,
        axisLabel: {
            //坐标轴刻度标签的相关设置。
            interval: 0, //设置为 1，表示『隔一个标签显示一个标签』
            //	margin:15,
            textStyle: {
                color: '#fff',
                fontStyle: 'normal',
                fontSize: 16,
                // fontWeight: 'bolder'
            },
            formatter: function (value) {
              if (value >= 10000) {
                return (value / 10000).toFixed(1).replace(/(\.0+$)/, "")+'w'; 
              } else {
                  return value.toLocaleString()
              }
            }
        },
        axisLine: {
            show: true, // X轴 网格线 颜色类型的修改
            lineStyle: {
                type: 'solid',
                opacity: '0.15',
                color: 'rgba(255,255,255,1)'
            },
        },
        splitLine: {
            show: true, // X轴线 颜色类型的修改
            lineStyle: {
                type: 'solid',
                color: 'rgba(77, 128, 254, 0.2)',
            },
        },
    },
    yAxis: [
        {
            type: 'category',
            inverse: true,
            axisLabel: {
                show: true,
                margin: 25,
                textStyle: {
                    color: '#fff',
                    fontSize: '16',
                    fontWeight: 'bolder',
                },
            },
            splitLine: {
                show: false,
            },
            axisTick: {
                show: false,
            },
            axisLine: {
              show: true, // Y轴 网格线 颜色类型的修改
              lineStyle: {
                  type: 'solid',
                  opacity: '0.15',
                  color: 'rgba(255,255,255,1)'
              },
            },           
            data: yLabel,
        },
    ],
    series: [
        {
            name: '上周应用活跃量',
            type: 'bar',
            zlevel: 1,
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                        {
                            offset: 0,
                            color: '#F39348',
                        },
                        {
                            offset: 1,
                            color: '#FFD042',
                        },
                    ]),
                },
            },
            barWidth: 23,
            data: yData,
            label: {// 右侧label数字
              normal: {
                  show: true,
                  position: 'right',
                  formatter: function(params) { return params.value.toLocaleString()},
                  color:'#fff',
                  fontSize:'14px'
              }
          }, 
        }
    ],
}
  return option;

}